<?php

class Country_Widget_ContentController extends Engine_Content_Widget_Abstract {
	
	/**
	 * Redirect to other widget
	 */
	public function indexAction() {
		$viewer = Engine_Api::_()->user()->getViewer();
        $this->view->subject = $subject = Engine_Api::_()->core()->getSubject();
 
        if(!$subject->getIdentity()) {
          return $this->setNoRender();
        }
        
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->listingType = $type = $request->getParam('type');
		$this->view->listingId = $listingType_id = $request->getParam('listingtype_id',0);
        $request->setParam('id',NULl);
    
        $widget = Country_Api_Core::$sitereview[$type];
        
        // Get content of other widget based on param "act"
		$content = '';
		try {
		    /*$structure = array (
				'type' => 'widget', 
				'name' => 'country.listtypes-categories', 
				'request' => $request, 
				'action' => 'index'
			);
			
			// Create element (with structure)
			$element = new Engine_Content_Element_Container(array (
				'elements' => array (
					$structure
				), 
				'decorators' => array (
					'Children'
				)
			));
            $content = $element->render();
            */
            
            $structure = array (
				'type' => 'widget', 
				'name' => 'sitereview.navigation-sitereview', 
				'request' => $request, 
				'action' => 'index'
			);
			
			// Create element (with structure)
			$element = new Engine_Content_Element_Container(array (
				'elements' => array (
					$structure
				), 
				'decorators' => array (
					'Children'
				)
			));
            $content .= $element->render();
            
            $profile = $request->getParam('profile',0);
            $hasCategory = $request->getParam('hasCategory',false);
            $api = Engine_Api::_()->country();
            
            
            $content1 = '';
            if (!empty($type) && empty($hasCategory) && empty($profile) ) {
               
                $widgets = Country_Api_Core::$sitereview[$type];
                foreach( $widgets as $widget){
                    $wparams = $api->getParamWidget('sitereview_index_home_listtype_'.$listingType_id,$widget);
                    $request->setParams($wparams);
        			$structure = array (
        				'type' => 'widget', 
        				'name' => $widget, 
        				'request' => $request, 
        				'action' => 'index'
        			);
        			
                    
        			// Create element (with structure)
        			$element = new Engine_Content_Element_Container(array (
        				'elements' => array (
        					$structure
        				), 
        				'decorators' => array (
        					'Children'
        				)
        			));
                    
        			$content1 .= $element->render();
                }
            } 
            
            if ($hasCategory && empty($profile)) {
                $widgets = Country_Api_Core::$sitereview_browse[$type];
                foreach( $widgets as $widget){
                    $wparams = $api->getParamWidget('sitereview_index_index_listtype_'.$listingType_id,$widget);
                    $request->setParams($wparams);
        			$structure = array (
        				'type' => 'widget', 
        				'name' => $widget, 
        				'request' => $request, 
        				'action' => 'index'
        			);
        			
                    
        			// Create element (with structure)
        			$element = new Engine_Content_Element_Container(array (
        				'elements' => array (
        					$structure
        				), 
        				'decorators' => array (
        					'Children'
        				)
        			));
                    
        			$content1 .= $element->render();
                }
            }
            
            if (!empty($profile)){
                $widgets = Country_Api_Core::$sitereview_profile[$type];
                foreach( $widgets as $widget){
                    $wparams = $api->getParamWidget('sitereview_index_index_listtype_'.$listingType_id,$widget);
                    $request->setParams($wparams);
        			$structure = array (
        				'type' => 'widget', 
        				'name' => $widget, 
        				'request' => $request, 
        				'action' => 'index'
        			);
        			
                    
        			// Create element (with structure)
        			$element = new Engine_Content_Element_Container(array (
        				'elements' => array (
        					$structure
        				), 
        				'decorators' => array (
        					'Children'
        				)
        			));
                    
        			$content1 .= $element->render();
                }
            }
            
            
		}
		catch (Exception $ex) {
                
		}
		
		// Set to current content
		$this->setContent($content.'<br>'.$content1);
		// return $this->setNoRender();
	}
}